home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python152_Src.lha / Python152_Source / Amiga / stat.c < prev    next >
C/C++ Source or Header  |  1996-04-14  |  2KB  |  107 lines

  1. RCS_ID_C="$Id: stat.c,v 4.2 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      stat.c - stat() for the netlib
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <errno.h>
  13.  
  14. #include <string.h>
  15. #include <stdlib.h>
  16.  
  17. /* DOS 3.0 and MuFS extensions to file info block */
  18. #include "fibex.h"
  19. #include "netlib.h"
  20. #include <proto/dos.h>
  21. #include <proto/utility.h>
  22.  
  23. int stat(const char *name, struct stat *st)
  24. {
  25.   short found;
  26.   register int rc = -1;
  27.   BPTR lock;
  28.  
  29.   if (st == NULL || ((1 & (long)st) == 1)) {
  30.     errno = EFAULT;
  31.     return -1;
  32.   }
  33.  
  34.   lock = Lock((STRPTR)name, SHARED_LOCK);
  35.  
  36.   if (found = lock != NULL) {
  37.     if (Examine(lock, __dostat_fib)) {
  38.       __dostat(__dostat_fib, st);
  39.       st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
  40.       rc = 0;
  41.     } else {
  42.       errno = EIO;
  43.     }
  44.   } else {
  45.     UBYTE errcode = IoErr();
  46.     
  47.     if (errcode == ERROR_OBJECT_IN_USE) {
  48.       rc = lstat(name, st);
  49.     } else {
  50.       set_errno(errcode);
  51.     }
  52.   }
  53.  
  54.   if (lock)
  55.     UnLock(lock);
  56.  
  57.   return rc;
  58. }
  59.  
  60. int lstat(const char *name, struct stat *st)
  61. {
  62.   /* Cannot lock - do examine via Examine()/ExNext() */
  63.   int rc = -1;
  64.   char *cname;
  65.  
  66.   if (st == NULL || ((1 & (long)st) == 1)) {
  67.     errno = EFAULT;
  68.     return -1;
  69.   }
  70.  
  71.   cname = malloc(strlen(name) + 1);
  72.  
  73.   if (cname) {
  74.     BPTR lock;
  75.     char *pp = PathPart(strcpy(cname, name));
  76.     *pp = '\0';
  77.  
  78.     if (lock = Lock(cname, SHARED_LOCK)) {
  79.       pp = FilePart((STRPTR)name);
  80.       
  81.       if (Examine(lock, __dostat_fib)) {
  82.     while (ExNext(lock, __dostat_fib)) {
  83.       if (Stricmp(pp, __dostat_fib->fib_FileName) == 0) {
  84.         __dostat(__dostat_fib, st);
  85.         st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
  86.         rc = 0;
  87.         break;
  88.       }
  89.     }
  90.       } 
  91.       if (rc != 0)
  92.     errno = ENOENT;
  93.     } else {
  94.       set_errno(IoErr());
  95.     }
  96.  
  97.     if(lock) UnLock(lock);        /* I.J. 13-Apr-96 */
  98.  
  99.     free(cname);
  100.   } else {
  101.     errno = ENOMEM;
  102.   }
  103.  
  104.   return rc;
  105. }
  106.  
  107.